package main.datastruc;

// Definition for singly-linked list.
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public static ListNode creList(int[] nums) {
        ListNode head = new ListNode(nums[0]);
        ListNode pre = head, next;
        for (int i = 1; i < nums.length; i++) {
            next = new ListNode(nums[i]);
            pre.next = next;
            pre = pre.next;
        }
        return head;
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
        //        if (obj == this) {
        //            return true;
        //        }
        //        if (!(obj instanceof ListNode)) {
        //            return false;
        //        }
        //        ListNode node = (ListNode) obj;
        //        return Objects.equals(val, node.val) /* && Objects.equals(next, node.next)*/;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
        //        return Objects.hash(val /*, next*/);
    }

    @Override
    public String toString() {
        ListNode node = this;
        StringBuilder str = new StringBuilder("[ ");
        while (node != null) {
            str.append(node.val).append(" -> ");
            node = node.next;
        }
        str.append("NULL ]");
        return str.toString();
    }
}
